/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "数据工具库.h"
#include <字符串数值互换.h>

// This is an example of an exported variable
int n数据工具库=0;

// This is an example of an exported function.
int fn数据工具库(void) {
	return 42;
}

// This is the constructor of a class that has been exported.
// see 数据工具库.h for the class definition
C数据工具库::C数据工具库() {
	return;
}

C_Key分配器::C_Key分配器() {
	m_末尾 = 0;
}

uint32 C_Key分配器::f_Gen() {
	uint32 key;
	/* = m_Key.size();
	
	if (m_Key.find(key) != m_Key.end()) {
		m_Key.insert(key);
	}
	else {
		key = m_回收站.back();
		m_回收站.pop_back();
	}*/

	if (m_回收站.size()) {
		key = m_回收站.back();
		m_回收站.pop_back();
	}
	else {
		key = m_末尾;
		++m_末尾;
	}

	return key;
}

void C_Key分配器::f_Move(uint32 key) {
	//m_Key.erase(key);
	m_回收站.push_back(key);
}

void C_Key分配器::f_Clear() {
	m_回收站.clear();
	m_末尾 = 0;
}



C_StrKey分配器::C_StrKey分配器() {
	m_末尾 = 0;
}

std::wstring C_StrKey分配器::f_Gen(std::wstring 前缀) {
	if (m_Key.find(前缀) != m_Key.end()) {
		while (前缀.size()) {
			auto t = 前缀.back();
			if (t >= '0' && t <= '9') {
				前缀.pop_back();
			}
			else {
				break;
			}
		}
		

		std::wstring newName;
		for (uint32 i = 0; i<-2; ++i) {
			newName = 前缀 + f_整数值转宽字符串(i);

			if (m_Key.find(newName) == m_Key.end()) {
				m_Key.insert(newName);
				return newName;
			}
		}
	}
	
	m_Key.insert(前缀);
	return 前缀;
}

void C_StrKey分配器::f_Move(std::wstring key) {
	//m_Key.insert(key);
	m_Key.erase(key);
}

void C_StrKey分配器::f_Clear() {
	m_Key.clear();
}





